<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path;
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>  
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设置-组织架构</title>				
    
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="<%=basePath%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    
    <link href="<%=basePath%>/hplus/css/k_style.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/zTree/zTreeStyle/metro.css" rel="stylesheet">
    <!-- 弹窗样式 -->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    
    
    
    <style>
    .ztree li a.curSelectedNode{
		background-color:#BEEBFF;
	}
	.switchery{																								
		width: 70px;
	}
	.s_box {
    border-top: 4px solid #1ab394;
    text-align: center;
	}
	
	.ztree li span.button.noline_close{background-position: -126px -84px;}									
	.ztree li span.button.noline_open{background-position: -105px -84px;}
	
	.s_popup .issue,.s_popup_box .s_popup_detailed,.s_popups .s_number_list,.issue_email,.k_issue{
    border-top: 4px solid #1ab394;
	}
	.s_popup .s_xk_issue p a,.s_popup_box .s_popup_detailed p a{
	background: #1ab394;
	}
	.bor{
	border:2px dashed #BFBFBF;
	width:100%;
	height:30px;
	margin:0px auto;
	line-height: 30px; /*设置line-height与父级元素的height相等*/
	text-align: center; /*设置文本水平居中*/
    overflow: hidden; /*防止内容超出容器或者产生自动换行*/
	}
	
	.s_ibox_content {
    border: 1px solid #e7eaec;
    padding: 0 0 0px;
    }
	

    </style>
    
</head>			
<body class="gray-bg" id="syBody">
    <div class="wrapper wrapper-content">
        <div class="col-sm-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 架构管理</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false" onclick="stopAccount();">停用账号</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body" style="margin-bottom:12px;">
                            <div class="col-sm-3 s_title">
  							<button  onclick="" class="btn btn-primary btn-outline" type="button" data-toggle="modal" data-target="#myModalDepartSet" >部门设置</button>
  							<button  onclick="exportDepartment();" class="btn btn-primary btn-outline" type="button">导出部门</button>
                            </div>
                            <div class="col-sm-5" style="text-align: center;line-height: 30px;">
                            <label class="col-sm-4 control-label">账号创建时间</label>
			                <div class="form-group col-sm-8" id="data_5">
			                    <div class="input-daterange input-group" id="datepicker" style="padding-left:0px">
			                        <input id="startTime" type="text" class="input-sm form-control"  name="start" readonly="" style="background-color: white;width:110px;" />
			                        <span class="input-group-addon">至</span>
			                        <input id="endTime" type="text" class="input-sm form-control"  name="end" readonly="" style="background-color: white;width:110px;"/>
			                    </div>
			                </div>  
                			</div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <input id="normalSearchValue" type="text" placeholder="填写手机号或姓名进行查找" class="input form-control">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn btn-primary" onclick="normalUserSearch(0);"> <i class="fa fa-search"></i> 搜索</button>
                                    </span>
                                </div>			
                            </div>
                        </div>
                        <div class="col-sm-2 s_sm_3">   
                            <div class="ibox float-e-margins">
                                <div class="ibox-content s_ibox_content" id="ztreediv" style="min-width:198px;" >		
                                <div class="k_title">组织架构</div>
                                	<div style="overflow-x:auto;">
                                	<!-- 引入zTree -->		
                                    <ul id="tree" class="ztree" ></ul>   
                                    </div>
                                 <input id = "baseTreeSelect" style="display:none;"></input>
                                 <input id = "baseTreeEditSelect" style="display:none;"></input>
                                 <!-- 新增部门纳入shiro权限控制 -->
                                 <shiro:hasPermission name="org:create_department">
                                 <div style="cursor:pointer;" class="bor" data-toggle="modal" data-target="#myModal6" onclick="initdepartmentSelect();"><font size="5" color="#BFBFBF" >+</font></div>
                                 </shiro:hasPermission>
                                </div>
                            </div>      															
                        </div>
                        
                        <div class="col-sm-10">
                            <div class="col-sm-12"> 					
                            
                                <div id="bmcurd"  class="s_btn_left">
                              		<!--  
                                    <button class="btn btn-primary" type="button" data-toggle="modal">编辑部门</button>
                                    -->
                                    <span>总计：</span>
                                    <span id="depNumShow"><span id="depNum"></span>个部门</span>
                                    <span id="userNumShow"><span id="userNum"></span>名成员</span>
                                </div>
                                <div class="s_btn_right">
                                	<!-- 配置角色纳入shiro权限控制 -->
                                    <shiro:hasPermission name="org:batch_configure">
                                    <button  class="btn btn-primary btn-outline" type="button" data-toggle="modal" href="<%=path%>/view/ui/selectRole" data-target="#role_modal" >配置角色</button>
                                    </shiro:hasPermission>
                                    <!-- 新增员工纳入shiro权限控制 -->
                                    <shiro:hasPermission name="org:manage_create">
                                    <button  onclick="addUserView();" class="btn btn-primary btn-outline" type="button">新增员工</button>
                                    </shiro:hasPermission>
                                </div>		
                            </div>
                            <div id="divUser"> 
                            
                           </div>

                        </div>          
                    </div>
                    <div id="tab-2" class="tab-pane">
                        <div class="panel-body">
                            <div class="col-sm-8 s_title">
                                <span><span id="userNumStop"></span>名成员</span>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <input id="stopSearchValue" type="text" placeholder="请填写手机号或姓名进行查找" class="input form-control">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn btn-primary" onclick="stopUserSearch(1)"; > <i class="fa fa-search"></i> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-12" style="margin-top:20px;padding-left:0;">
                         <div id="divUserStop"> 
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 选择角色弹框 -->
    <div  class="modal inmodal fade" id="role_modal" tabindex="-1" role="dialog"  aria-hidden="true" >
        <div class="modal-dialog modal-lg">
            <div class="modal-content" >
               
            </div>				
        </div>
    </div>

    <!-- 新建部门-->						
    <div  hidden="" class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">新建部门</h4>
                </div>
                <div class="text-center" style="width:100%;height:60px;">                    
                    <form method="get" class="form-horizontal col-sm-12" style="margin:20px 0;">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">部门类型</label>
                            <div class="col-sm-8 text-left">
                            <div class="radio i-checks">							
                                 <label><input id = "mechanismCheckedCreate" type="radio" checked="" value="option1" name="a"> <i></i>机构</label>
                             </div>
                             <div class="radio i-checks">
                                  <label><input id="teamCheckedCreate" type="radio" value="option2" name="a"> <i></i>团队</label>
                             </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color:red;vertical-align:middle;">&nbsp;*</span>部门名称</label>
                            <div class="col-sm-8">
                                <input id="bmNameCreate" maxlength="10"  type="text" class="form-control" placeholder="请勿超过10个字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color:red;vertical-align:middle;">&nbsp;*</span>上级部门</label>
                            <div class="col-sm-8" style="height:230px;overflow-y:auto" >
                             <ul id="treeCreate" class="ztree" ></ul>   
                            </div>
                            <input id ="parentDepartmentIdCreate" style="display:none;"></input>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">部门负责人</label>
                            <div class="col-sm-8">
                                <input id="bmLeaderName" type="text" class="form-control" placeholder="请填写负责人名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color:red;vertical-align:middle;">&nbsp;*</span>部门编号</label>
                            <div class="col-sm-8">
                                <input id="bmCode" type="text" class="form-control" maxlength="6">
                            </div>
                        </div>
                    </form>
                </div>
                 <div class="modal-footer" style="text-align:center;border-top:none;">
                     <button type="button" class="btn btn-outline btn-primary" data-dismiss="modal">取消</button>
                     <button type="button" class="btn btn-primary k_verify" onclick="createDepartmentInfo();">确定</button>
                 </div>
             </div>
        </div>
    </div> 
    
    <!-- 编辑部门 -->						
    <div  hidden="" class="modal inmodal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">编辑部门</h4>
                </div>
                <div class="text-center" style="width:100%;height:60px;">                    
                    <form method="get" class="form-horizontal col-sm-12" style="margin:20px 0;">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">部门类型</label>
                            <div class="col-sm-8 text-left">
                            <div class="radio i-checks ">							
                                 <label><input id="mechanismCheckedEdit" type="radio" value="option1"> <i></i>机构</label>
                             </div>
                             <div class="radio i-checks">
                                  <label><input id="teamCheckedEdit" type="radio" value="option2"> <i></i>团队</label>
                             </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color:red;vertical-align:middle;">&nbsp;*</span>部门名称</label>
                            <div class="col-sm-8">
                                <input id="bmNameEdit" type="text" class="form-control" placeholder="请勿超过10个字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">部门负责人</label>
                            <div class="col-sm-8">
                                <input id="leaderNameEdit" type="text" class="form-control" placeholder="请填写负责人名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color:red;vertical-align:middle;">&nbsp;*</span>部门编号</label>
                            <div class="col-sm-8">
                                <input id="bmCodeEdit" type="text" class="form-control" maxlength="6">
                            </div>
                        </div>
                    </form>
                </div>
                 <div class="modal-footer" style="text-align:center;border-top:none;">
                     <button type="button" class="btn btn-outline btn-primary" data-dismiss="modal">取消</button>
                     <button type="button" class="btn btn-primary k_verify" onclick="updateDepartmentInfo();">确定</button>
                 </div>
             </div>
        </div>
    </div> 
    
    
    <!-- 删除部门 -->						
    <div  hidden="" class="modal inmodal fade" id="myModalDelete" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm" style="width:500px">
            <div class="modal-content">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">删除部门</h4>
                </div>
                <div class="text-center" style="width:100%;height:60px;">                    
                    <form method="get" class="form-horizontal col-sm-12" style="margin:20px 0;">
                        <div class="form-group">
<!--                        <div class="col-sm-12">
                        	<span>删除部门后根据部门统计的数据将无法查看，是否将数据迁移至其他部门？</span>
                        	</div>
                        	<div style="height:20px;"></div> 
                            <label class="col-sm-3 control-label" style="color:red;">请选择：</label>
                            <div class="col-sm-8 text-left">
                             <select class="form-control" >
                                    <option>迁移数据功能暂不开放，敬请期待</option>
                             </select>
                            </div> -->
                            
                            <div class="col-sm-12">
                        	<span>删除部门后将无法恢复，确认进行删除吗？</span>
                            </div> 
                        </div>
                       
                    </form>
                </div>
                 <div class="modal-footer" style="text-align:center;border-top:none;">
                     <button type="button" class="btn btn-outline btn-primary" data-dismiss="modal">取消</button>
                     <button type="button" class="btn btn-primary k_verify" onclick="delDepartment()">确定</button>
                 </div>
             </div>
        </div>
    </div>
     
    <!-- 部门设置 -->
    <div  hidden="" class="modal inmodal fade" id="myModalDepartSet" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header" style="padding: 15px 15px 10px;">
                    <button type="button" class="close" onclick = "closeTabReload();"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="text-left">部门设置</h4>
                </div>
                
                <div class="col-sm-12">
				<div class="col-sm-8 text-center" style="margin-top:20px;">
					部门编码应用至全员营销
				</div>	
				<div class="col-sm-4" style="margin-top:20px;">
			    <div class="switch">
                     <div class="onoffswitch">
                       <input class="onoffswitch-checkbox" id="businessSwitch" type="checkbox" onclick="clickBusiness();">
                         <label class="onoffswitch-label" for="businessSwitch">
                           <span class="onoffswitch-inner"></span>
                           <span class="onoffswitch-switch"></span>
                         </label>
                     </div>
                </div>
				</div>	
				</div>	
				
				<div class="col-sm-12">
				<h5 class="page-header"></h5>
				</div>
				
                <div class="text-center">                    
                    <form method="get" class="form-horizontal col-sm-12" style="margin:0px 20px 10px 0px;">
                        <img src="${pageContext.request.contextPath}/hplus/img/sjdr.png" style="cursor:pointer;" onclick="fileSelect();"/>
                        <span id="filePath"></span>		
             		  <div class="text-center">
                	    <input class="col-sm-3" id="file" type="file" name="file" onchange="fileSelected();" style="display:none;">
               		 </div>		
                    </form>
                </div>			
            
                <div class="text-center">
                	<button type="button" class="btn btn-primary k_verify" id="submit"  >导入部门</button>
                </div>			
                <div class="text-center">						
                	<span id="importAlertSpan" style="color:red;display:none;">请选择需要导入的excel</span>
                </div>			
                
                <div class="form-group" style="padding: 20px 0 20px;display:none;" id="exportPro">		
                    <label class="col-sm-3 control-label" style="text-align:right;">正在导入</label>										
                    <div class="col-sm-8" style="margin-top:6px;">
                        <div class="progress progress-striped active" style="height:8px;">
                            <div style="width: 100%;height:8px;" aria-valuemax="70" aria-valuemin="0" aria-valuenow="70" role="progressbar" class="progress-bar">
                            </div>			
                        </div>			
                    </div>								
                </div>			
                <div class="form-group text-center" id="successShow" style="padding: 10px 0 10px;display:none;">	
                    <p>已成功导入<span class="text-navy" id="sucNums" ></span>条用户信息，其中<span id="errNums"></span>条数据无法使用请<span class="text-navy" style="cursor:pointer;" onclick="exportError();">导出</span>查看</p>
                <div class="text-center" style="padding-top:10px;">
                	<button type="button" class="btn btn-primary k_verify" onclick="closeTabReload();">确定</button>
                </div>	
                </div>
                <div class="form-group text-center" id="errorShow" style="padding: 10px 0 10px;display:none;">
                    <p><span style="color:red;">导入的部门数据不能超过500条，请核对*</span></p>
                </div>
                
                <div class="form-group" style="padding: 15px 15px 10px;" id="importInfoDesc">
                    <p>导入更多部门请<span class="text-navy"><a href="<%=basePath%>/excel/departmentTemplate.xlsx">下载导入模板</a></span>后，根据模板格式填写数据，并进行导入</p>
                </div>
             </div>
        </div>
    </div> 
    
    
    	

    <script src="<%=basePath%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=basePath%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=basePath%>/hplus/js/content.min.js?v=1.0.0"></script>
    <script src="<%=basePath%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/iCheck/icheck.min.js"></script>						
    <script src="<%=basePath%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    <script src="<%=basePath%>/hplus/js/demo/form-advanced-demo.min.js"></script>
    <script src="<%=basePath%>/hplus/js/plugins/footable/footable.all.min.js"></script>	
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    
    <script src="<%=basePath%>/hplus/js/plugins/zTree/jquery.ztree.all-3.5.min.js"></script>			
	<!-- 弹窗插件 -->
	<script src="<%=basePath%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<!-- 弹窗脚本 -->
	<script type="text/javascript" src="<%=basePath%>/js/marketing/dialog.js"></script>
	
	<!-- 页面上所展示的树 -->
	<script type="text/javascript" src="<%=basePath%>/js/system/organizationalStructureTree.js"></script>
	
	<!-- 该页面所需的公共方法 -->
	<script type="text/javascript" src="<%=basePath%>/js/system/publicTools.js"></script>
	
	<!-- 上传相关js控件 -->
	<script type="text/javascript" src="<%=basePath%>/js/system/jquery.ui.widget.js"></script>
	
	<!-- 上传控件 -->
	<script type="text/javascript" src="<%=basePath%>/js/system/jquery.fileupload.js"></script>						
  <script>			
  
  
  
	   //全局ajax同步，无需异步请求
		$.ajaxSetup({  			
			async : false  
		});      
  
	       
		//页面自加载方法
        $(function(){
        	
            //初始化部门基础树、新建部门树、编辑部门树、
        	initZtree();
            
            //初始化正常用户选项卡,如果部门ID为空，则取第一个部门下的全部员工
            initUser('');
            
    		//统计正常的用户数量及未停用的用户数量以及部门的数量
        	initUserDepartmentNum();
    		
    		//初始化日期控件
    		initDatepicker();
    		
    		//编辑部门按钮监听
    		initEditButtonMonitor();
        	
    		//初始化停用用户数量
			stopUserSearch(1);		
    		
    		//为zTree所有的节点增加属性
    		initZtreeDiv();
    		
    		//初始化部门编号
    		initDepartNum();
    		
    		//初始化导入部门层级监听
    		importDepartment();
    		
    		//初始化全员营销状态
    		departmentSet();
        });
		
        //为zTree所有的节点增加属性
		function initZtreeDiv(){

	        var aTree = $("a[id^='tree_']");	
	        for(var i = 0; i < aTree.length; i++) {
	        	//1、拿到要进行回显的值
        		var title = $("#"+aTree[i].id).attr("title");
	        	//2、清空div的title标题
        		$("#"+aTree[i].id).attr("title","");
	        	//3、拿到部门名称
	        	var departName = title.split(",")[0];
	        	//4、拿到部门数量
	        	var departNum = title.split(",")[1];
	        	//5、拿到负责人
	        	var departLeader = title.split(",")[2];
	        	//6、拿到图片路径
	        	var departImg = title.split(",")[5];
	        	//7、拿到部门编码
	        	var departCode = title.split(",")[3];
	        	var html = '';
        			html += '<div class="col-sm-12" style="width:400px;height:120px;">';			
        			html += '<div class="col-sm-6" style="margin-top:10px;margin-left:20px;">';			
        			html += '<span style="font-size:15px;font-weight:bold;">' + departName + '</span>';
        			html += '</div>';
            		html += '<div class="col-sm-2" style="margin-top:10px;margin-left:20px;">';			
        			html += '<img src="'+departImg+'"></img>';
        			html += '</div>';			
            		html += '<div class="col-sm-12" style="margin-top:5px;margin-left:20px;">';			
        			html += '<span style="font-size:13px;">' + departNum + '</span>';
        			html += '</div>';
                	html += '<div class="col-sm-12" style="margin-top:5px;margin-left:20px;">';			
        			html += '<span style="font-size:13px;">' + departLeader + '</span>';
        			html += '</div>';
                    html += '<div class="col-sm-12" style="margin-top:5px;margin-left:20px;">';			
        			html += '<span style="font-size:13px;">' + departCode + '</span>';
        			html += '</div>';				
        			//html += '<div class="col-sm-12" style="margin-top:5px;margin-left:5px;width:265px;">';					
        			//html += '<h5 class="page-header"></h5>';
        			//html += '</div>';
        			//html += '<div class="col-sm-12" style="margin-top:5px;margin-left:200px;">';					
        			//html += '<span class="text-navy" style="cursor:pointer;">编辑</span>&nbsp;&nbsp;<span class="text-navy" style="cursor:pointer;">删除</span>';
        			//html += '</div>';
	        		html += '</div>';		
	        		
	        	$("#"+aTree[i].id).popover({
	                html: true, // 为true的话，data-content里就能放html代码了		
	                content:html,
	                trigger:'hover',
	                placement:'top',		
	                placement: "right",
	                delay: {hide: 100}
	        	}).on('shown.bs.popover', function (event) {
	                var that = this;
	                $(this).parent().find('div.popover').on(' ', function () {
	                    $(that).attr('in', true);
	                }).on('mouseleave', function () {
	                    $(that).removeAttr('in');
	                    $(that).popover('hide');
	                });
	            }).on('hide.bs.popover', function (event) {
	                if ($(this).attr('in')) {
	                    event.preventDefault();
	                }
	            });
	        	 $("#"+aTree[i].id).popover();
	        }		
		}
					
		
		//初始化部门基础树			
		function initZtree(){
        	//保存所有的部门节点数据
        	var zNodes =[];
			//发送ajax请求，从DB中查询该企业下，包含层级关系的全部部门
	      	var url="<%=path%>/department/ajaxSelectAllDepartment";
        	$.post(url, {
    		}, function(data) {
    			var realData = data.data;
    			if (data.status == 200) {
    				for(var i=0;i<realData.length;i++){
    					var treeData = null;
    					//机构团队用不同的图标
    					if(realData[i].companyType == 1){
    					   var name = realData[i].name;
    					   if(name.length > 8){
    						   name = name.substring(0,8) + "...";
    					   }
    					   var userNum = realData[i].title.split(",")[3];
    					   if(userNum > 0){
    						   treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:name,font:{'font-weight':'bold'},title:realData[i].name+","+realData[i].title+","+"${pageContext.request.contextPath}/images/system/mechanismIcon.png",open:true,icon:"${pageContext.request.contextPath}/images/system/mechanismIcon.png"};  
    					   }else{
    						   treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:name,font:{'color':'#BBBBBB'},title:realData[i].name+","+realData[i].title+","+"${pageContext.request.contextPath}/images/system/mechanismIcon.png",open:true,icon:"${pageContext.request.contextPath}/images/system/mechanismIcon.png"};
    					   }
    					   
    					}else{
     					  var name = realData[i].name;					
    					  if(name.length > 8){
    						  name = name.substring(0,8) + "...";
    					  }
    					  var userNum = realData[i].title.split(",")[3];
    					  if(userNum > 0){
    					       treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:name,font:{'font-weight':'bold'},title:realData[i].name+","+realData[i].title+","+"${pageContext.request.contextPath}/images/system/teamIcon.png",open:true,icon:"${pageContext.request.contextPath}/images/system/teamIcon.png"};
    					  }else{
    					       treeData = {id:realData[i].id,companyType:realData[i].companyType,leaderName:realData[i].leaderName,pId:realData[i].parentDeptId, name:name,font:{'color':'#BBBBBB'},title:realData[i].name+","+realData[i].title+","+"${pageContext.request.contextPath}/images/system/teamIcon.png",open:true,icon:"${pageContext.request.contextPath}/images/system/teamIcon.png"};	  
    					  }
    					}
    					zNodes.push(treeData);
    				}
    				zTree(zNodes);
    				zTreeCreate(zNodes);	
    			}else{		
	        		errorDialog(data.message);
	        	}
    		}); 
		}
		
		
		//统计正常的用户数量及未停用的用户数量以及部门的数量
		function initUserDepartmentNum(){
			//直接获取所有部门树的节点，就是部门的总数
		     var nodes = getAllTreeNote();
		     if(nodes.length > 0){
   			   //部门数量赋值
   			   $("#depNum").text(nodes.length);
		     }else{
		       $("#depNum").text(0); 
		     }
		     			
			//发送ajax请求，从DB中查询该企业下，正常的用户数量
			$("#userNum").text(initUserStopAndStartNum(0));
			
		}
        
		
		//根据部门ID初始化用户选项卡,如果部门ID为空，则取第一个部门下的全部员工
		function initUser(departmentId){
			 
			 var departmentBySearchId = departmentId;
			 //如果传入的部门id为空，则取部门树第一个节点的部门，调用ajax，查询该部门下的用户
			 if(departmentId == ''){
			     var nodes = getAllTreeNote();
			     if(nodes.length > 0){
			    	 departmentBySearchId = nodes[0].id;
			     }
			 }
			 //默认选中第一个部门，在此标记
			 $("#baseTreeSelect").val(departmentBySearchId);
			 
			 //设置树的选中状态
			 setTreeNoteSelect("tree",departmentBySearchId);
			
			//发送ajax请求,从DB中根据部门查询用户信息(部门ID为空，则取企业第一个部门下的全部员工)
			 var url="<%=path%>/account/ajaxSelectUserByDepartment";
	         $.post(url, {
	        	"departmentId":departmentBySearchId, //部门id
	        	"status":0 //状态
	    	 }, function(data) {
	    		var realData = data.data;
	    		if (data.status == 200) {
	    			//根据查询出来的用户集合，动态增加正常用户div选项卡
	    			divUserCreate(realData);
	    		}else{
					 var html = "";
				 	 html += "<div class='col-sm-12 text-center'>";
				 	 html += '<img style="width:60%;height:60%" src="<%=path%>/images/system/noEmployees.png" />';
				 	 html += "<p><span style='font-weight:bold;font-size:18px;'>此级部门下还没有员工哦</span></p>";
				 	 html += "</div>";
	           	     $('#divUser').html(html); 
		        }			
	    	}); 
		}
		
		//初始化状态为正常的及状态为停用的用户总量
		function initUserStopAndStartNum(status){
			 var url="<%=path%>/account/ajaxSelectUserByDepartment";
			 var allUserNum = 0;
	         $.post(url, {
		        	"status":status //状态
		    	 }, function(data) {
		    		var realData = data.data;
		    		if (data.status == 200) {
		    			allUserNum = realData.length;
		    		}else{		
			        	//errorDialog(data.message);
			        }
		    	}); 
			return allUserNum;
		}
		
		
		
		//根据查询出来的用户集合，动态增加正常用户div选项卡
		function divUserCreate(users){
        	var html = ''; 
            //循环查询出的状态为正常的用户
            for(var o=0;o<users.length;o++){
        		html += "<div class='col-sm-3'>";   
                html += "<div class='contact-box' onclick='editUser(\""+users[o].id+"\");'>";
            //是否可以进行账户停用，需要加入shiro权限控制
    		<shiro:hasPermission name="org:manage_stop">
            //客户最大超级管理员不能删除、客户自己本身不能删除
            if(users[o].isSuper !=1 && users[o].currentUser !=1){
                html += '<a class="close-link">'; 
                html += "<i class='fa fa-times' style='z-index:999' onclick='stopOrStartUser(\""+users[o].id+"\",1)'></i>"; 
                html += '</a>'; 
             }						
            </shiro:hasPermission>
            var htmlCheck = "";
            	//勾选用户的复选框
           		htmlCheck+='<label class="checkbox-inline i-checks">';
	            htmlCheck+='<div class="icheckbox_square-green" style="position: relative;">';			
	            htmlCheck+=' <input name="c'+users[o].id+'" type="checkbox" value="c'+users[o].id+'" style="position: absolute; opacity: 0;">';
	            htmlCheck+='<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>';
	            htmlCheck+='</div>';
	            htmlCheck+='</label>';
	            var userName = users[o].name;					
	            if(userName.length > 5){
	            	userName = users[o].name.substring(0,5) + "...";
	            }
            	if(userName == "" || userName.length == 0 || userName == null){
            		userName = "...";
            	}
                html += htmlCheck +"<strong title='"+users[o].name+"'>"+userName+"</strong><br/>"; 	
                html += '';		
            //如果没有角色，显示无权限			
            if(typeof(users[o].roleName)=="undefined" || users[o].roleName == '' || users[o].roleName == null){ 
                html += '<span style="font-size:11px" class="text-navy" title = "无权限">角色权限：无权限</span><br/>'; 
            }else{
            	var roleName = users[o].roleName;
            	if(roleName.length > 7){
            		roleName = roleName.substring(0,7) + "...";
            	}
                html += '<span style="font-size:11px" class="text-navy" title = "'+users[o].roleName+'">角色权限：'+roleName+'</span><br/>'; 
             } 
                html += '<span style="font-size:11px">数据权限：'+getAuthDataName(users[o].userIdentity)+'</span><br/>'; 
                html += '手机号：'+users[o].account+''; 
                html += '<div class="clearfix"></div>'; 		
                html += '</div>'; 
                html += '</div>';
             }		
         	 //在html中赋值，增加div选项卡
        	 $('#divUser').html(html); 
         	 
         	 //初始化iCheck控件,该控件一定要最后初始化，为的是在页面所有icheck都生成完毕后初始化
         	 initICheck();
         	 //重新绑定radio控件
             initEditButtonMonitor();
		}
		

		//新增部门基础信息
		function createDepartmentInfo(){
			//正则表达式，判断必须是字母或数字
			var reg = /^[0-9a-zA-Z]+$/;
			//默认为用户选择的基础树的节点
			$("#parentDepartmentIdCreate").val($("#baseTreeSelect").val());
			//机构选中状态
			var mechanismChecked = $('#mechanismCheckedCreate').is(':checked');
			//团队选中状态
			var teamChecked = $('#teamCheckedCreate').is(':checked');
            //部门类型 1、机构 2、团队
            var departType = 1;
            if(mechanismChecked){
            	departType = 1;
            }else if(teamChecked){
            	departType = 2;
            }

            //获取用户选择的上级部门信息
            var parentId = $("#parentDepartmentIdCreate").val();
            //获取用户填写的部门名称
            var bmName = $("#bmNameCreate").val();
            //获取用户填写的部门编码
            var bmCode = $("#bmCode").val();
            //获取用户填写的部门负责人名称
            var bmLeaderName  = $("#bmLeaderName").val();
            if(bmLeaderName.length > 10){
            	promptDialog("部门负责人请勿超过10个字！");
            	return;
            }
			if(bmName.length > 10){
				promptDialog("部门名称请勿超过10个字！");
			}else if(trim(bmName) == ""){
				promptDialog("请填写部门名称！");
			}else if(trim(bmCode) == ""){
				promptDialog("请填写部门编码！");
				return;
			}else if(bmCode.length != 6){
				promptDialog("部门编码只能是6位字母或数字!");
				return;
			}else if(!reg.test(bmCode)){
				promptDialog("部门编码只能是6位字母或数字！");
				return;
			}else{
				//部门信息入库
				 var url="<%=path%>/department/ajaxCreateDepartment";
				 var allUserNum = 0;
		         $.post(url, {
			        	"companyType":departType,
			        	"name":bmName,
			        	"leaderName":bmLeaderName,
			        	"parentDeptId":parentId,
			        	"code":bmCode
			    	 }, function(data) {
			    		var realData = data.data;
			    		if (data.status == 200) {
			    			//操作成功刷新页面
		 					window.location.reload();
			    		}else{		
				        	errorDialog(data.message);
				        }
			    	}); 
			}
		}

		//初始化新增部门时要回显的部门
		function initdepartmentSelect(){
			setTreeNoteSelect("treeCreate",$("#baseTreeSelect").val());
		}
		
		
		//编辑部门基础信息
		function updateDepartmentInfo(){
			//正则表达式，判断必须是字母或数字
			var reg = /^[0-9a-zA-Z]+$/;
			//机构选中状态
			var mechanismChecked = $('#mechanismCheckedEdit').is(':checked');
			//团队选中状态
			var teamChecked = $('#teamCheckedEdit').is(':checked');
            //部门类型 1、机构 2、团队
            var departType = 1;
            if(mechanismChecked){
            	departType = 1;
            }else if(teamChecked){
            	departType = 2;
            }
            //获取用户填写的部门名称
            var bmName = $("#bmNameEdit").val();
            //获取用户填写的部门编码
            var bmCode = $("#bmCodeEdit").val();
            //获取用户填写的部门负责人名称
            var bmLeaderName  = $("#leaderNameEdit").val();
            if(bmLeaderName.length > 10){
            	promptDialog("部门负责人请勿超过10个字！");
            	return;
            }
			if(bmName.length > 10){
				promptDialog("部门名称请勿超过10个字！");
			}else if(trim(bmName) == ""){
				promptDialog("部门名称不能为空！");
			}else if(trim(bmCode) == ""){
				promptDialog("请填写部门编码！");
				return;
			}else if(bmCode.length != 6){
				promptDialog("部门编码只能是6位字母或数字!");
				return;
			}else if(!reg.test(bmCode)){
				promptDialog("部门编码只能是6位字母或数字！");
				return;
			}else{
				//部门信息编辑
				 var url="<%=path%>/department/ajaxEditDepartment";
				 var allUserNum = 0;
		         $.post(url, {
		        	 	"id":$("#baseTreeEditSelect").val(),
			        	"companyType":departType,
			        	"name":bmName,
			        	"leaderName":bmLeaderName,
			        	"code":bmCode
			    	 }, function(data) {
			    		var realData = data.data;
			    		if (data.status == 200) {
			    			//操作成功刷新页面
		 					window.location.reload();
			    		}else{		
				        	errorDialog(data.message);
				        }
			    	}); 
			}
		}
		
		
		//初始化icheck控件
		function initICheck(){
			$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})
		}
        
		
		//初始化日期控件
		function initDatepicker(){
			var starttime = new Date();
	     	var date2 = new Date();
	     	date2.setDate(date2.getDate() - 7);		
	       	$("#startTime").datepicker({autoclose : true});
	     	$("#endTime").datepicker({autoclose : true});					
	     	$("#endTime").datepicker('setDate' ,starttime);
	    	$("#startTime").datepicker('setDate',date2);
		}		
		
		
		//根据用户业务身份标识判断返回用户的数据权限名称
		//用户业务身份(个人1、管理2、个人无归属数据3、部门无归属数据4)
		function getAuthDataName(userIdentity){
			if(userIdentity == 1){
				return '个人';
			}else if(userIdentity == 2){
				return '部门';
			}else if(userIdentity == 3){
				return '个人、无归属';
			}else if(userIdentity == 4){
				return '部门、无归属';
			}
			
		}
		
		//根据用户名手机号模糊查询状态为正常的用户信息
		function normalUserSearch(status){
			//alert($("#startTime").val() +"---"+ $("#endTime").val() );
			//if($("#normalSearchValue").val() == ''){
			//	window.location.reload();
			//	return;
			//}
			if($("#normalSearchValue").val() == null || $("#normalSearchValue").val() == ""){
                var startTime = new Date($("#startTime").val() + " 00:00:00");
                var endTime = new Date($("#endTime").val() + " 00:00:00");

            }

			 //清空div选项卡
	    	 $('#divUser').html(''); 
			 var url="<%=path%>/account/ajaxSelectUserByKeyWord";
	         $.post(url, {
		        	"keyWord":$("#normalSearchValue").val(), //关键词
		        	"status":0,  //状态
		        	"startTime":startTime,
		        	"endTime":endTime
		    	 }, function(data) {
		    		var users = data.data;
		    		if (data.status == 200) {
		    			var arr = [];
		    			for(var i=0; i<users.length;i++){
		    				arr.push(users[i].departmentName);
		    			}
		    			var s = new Set(arr);
		    			var html = "";
		    			//遍历查询出的所有用户的部门
		    			for (var departmentName of s) {
                            html += '<div style="float:left;width:100%;">';
                            var newDepartmentName = departmentName.substring(0,20) + "...";
                            html += '<p><span style="margin-left:15px;font-weight:bold;" title="'+departmentName+'">'+newDepartmentName+'</span></p>';  //指定部门
		                    //循环查询出的状态为正常的用户
		                    for(var o=0;o<users.length;o++){
                                $("#depNumShow").hide();

                                $("#userNum").html(users.length);
		                    	if(departmentName == users[o].departmentName){
		                		html += "<div class='col-sm-3'>";
		                        html += "<div class='contact-box' onclick='editUser(\""+users[o].id+"\");'>";
		                        
		                    //是否可以进行账户停用，需要加入shiro权限控制
		                    <shiro:hasPermission name="org:manage_stop">
		                    //客户最大超级管理员不能删除、客户自己本身不能删除
		                    if(users[o].isSuper != 1 && users[o].currentUser !=1){
		                        html += '<a class="close-link">'; 
		                        html += "<i class='fa fa-times' onclick='stopOrStartUser(\""+users[o].id+"\",1)'></i>"; 
		                        html += '</a>'; 
		                     }		
		                    </shiro:hasPermission>
		                    var htmlCheck = "";
		                    	//勾选用户的复选框
		                   		htmlCheck+='<label class="checkbox-inline i-checks">';
		        	            htmlCheck+='<div class="icheckbox_square-green" style="position: relative;">';			
		        	            htmlCheck+=' <input name="c'+users[o].id+'" type="checkbox" value="c'+users[o].id+'" style="position: absolute; opacity: 0;">';
		        	            htmlCheck+='<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins>';
		        	            htmlCheck+='</div>';
		        	            htmlCheck+='</label>';
		        	            var userName = users[o].name;
		        	            if(userName.length > 5){
		        	            	userName = users[o].name.substring(0,5) + "...";
		        	            }
		                    	if(userName == "" || userName.length == 0 || userName == null){
		                    		userName = "...";
		                    	}
		                        html += htmlCheck +"<strong  title='"+users[o].name+"'>"+userName+"</strong><br/>"; 	
		                        html += '';
		                    //如果没有角色，显示无权限			
		                    if(typeof(users[o].roleName)=="undefined" || users[o].roleName == '' || users[o].roleName == null){ 
		                        html += '<span style="font-size:11px" class="text-navy" title = "无权限">角色权限：无权限</span><br/>'; 
		                    }else{
		                    	var roleName = users[o].roleName;
		                    	if(roleName.length > 7){
		                    		roleName = roleName.substring(0,7) + "...";
		                    	}
		                        html += '<span style="font-size:11px" class="text-navy" title = "'+users[o].roleName+'" >角色权限：'+roleName+'</span><br/>'; 
		                     } 
		                        html += '<span style="font-size:11px">数据权限：'+getAuthDataName(users[o].userIdentity)+'</span></br>'; 
		                        html += '手机号：'+users[o].account+''; 
		                        html += '<div class="clearfix"></div>'; 		
		                        html += '</div>'; 
		                        html += '</div>';

		                    	}
		                     }		
		    			    html += '</div>';	
		    			}
		    	           //在html中赋值，增加div选项卡
		    	           $('#divUser').html(html); 
		    		}else{		
						 var html = "";
					 	 html += "<div class='col-sm-12 text-center'>";
					 	 html += '<img style="width:60%;height:60%" src="<%=path%>/images/system/noEmployees.png" />';
					 	 html += "<p><span style='font-weight:bold;font-size:18px;'>抱歉，没有找到相关员工</span></p>";
					 	 html += "</div>";
		           	     $('#divUser').html(html);
                        $("#userNum").html(0);
			        }
		    	}); 
	         //初始化日期控件
	         initICheck();
		}
		//根据用户名手机号模糊查询状态为停用的的用户信息
		function stopUserSearch(status){
			//if(trim($('#divUserStop').html()) != '' && $("#stopSearchValue").val() == ''){
			//	window.location.reload();
			//	return;
			//}
			
			 //清空div选项卡				
	    	 $('#divUserStop').html(''); 
			 var url="<%=path%>/account/ajaxSelectUserByKeyWord";
	         $.post(url, {
		        	"keyWord":$("#stopSearchValue").val(), //关键词
		        	"status":status  //状态
		    	 }, function(data) {
		    		var users = data.data;
		    		if (data.status == 200) {
		    			var arr = [];
		    			for(var i=0; i<users.length;i++){
		    				arr.push(users[i].departmentName);
		    			}
		    			var s = new Set(arr);
		    			var html = "";
		    			//遍历查询出的所有用户的部门
		    			for (var departmentName of s) { 
		            		html += '<div style="float:left;width:100%;">';
		            		var newDepartmentName = departmentName.substring(0,20) + "...";
                            html += '<p><span style="margin-left:15px;font-weight:bold;" title="'+departmentName+'">'+newDepartmentName+'</span></p>';  //指定部门
		                    //循环查询出的状态为正常的用户
		                    for(var o=0;o<users.length;o++){
		                    	
		                    	if(departmentName == users[o].departmentName){
		                    	
		                		html += "<div class='col-sm-3'>";   
		                        html += '<div class="contact-box" style="height:135px;">';		
		        	            var userName = users[o].name;
		        	            if(userName.length > 5){
		        	            	userName = users[o].name.substring(0,5) + "...";
		        	            }
		                    	if(userName == "" || userName.length == 0 || userName == null){
		                    		userName = "...";
		                    	}
		                        html += '<strong title='+users[o].name+'>'+userName+'</strong><br/>'; 	
		                        html += '';
		                    //如果没有角色，显示无权限			
		                    if(typeof(users[o].roleName)=="undefined" || users[o].roleName == '' || users[o].roleName == null){ 
		                        html += '<span style="font-size:11px" class="text-navy">角色权限：无权限</span><br/>'; 
		                    }else{
		                    	var roleName = users[o].roleName;
		                    	if(roleName.length > 7){
		                    		roleName = roleName.substring(0,7) + "...";
		                    	}
		                        html += '<span style="font-size:11px" class="text-navy" title = "'+users[o].roleName+'">角色权限：'+roleName+'</span><br/>'; 
		                     } 
		                        html += '<span style="font-size:11px">数据权限：'+getAuthDataName(users[o].userIdentity)+'</span><br/>'; 
		                        html += '手机号：'+users[o].account+''; 
		                        //获取指定格式的停用时间
		                        var stopTime = (new Date(users[o].stopTime)).Format("yyyy-MM-dd")  
		                        html += '<p class="s_time">时间：<span>'+stopTime+'</span>'; 		
		                        //停用账号，删除按钮纳入shiro权限控制
                                <shiro:hasPermission name="org:stop_user_delete">
		                    	html += "<a href='#' onclick='stopOrStartUser(\""+users[o].id+"\",2)'>删除</a>"; 
                                </shiro:hasPermission>
                                //停用账号，启用按钮纳入shiro权限控制
                                <shiro:hasPermission name="org:stop_user_start">
		                    	html += "<a href='#' style='color:#1ab394' class='s_start_using' onclick='stopOrStartUser(\""+users[o].id+"\",0,\""+users[o].account+"\")'>启用</a>";
                                </shiro:hasPermission>
		                    	html += '</p>'; 
		                    	html += '<div class="clearfix"></div> '; 			
		                        html += '</div>'; 
		                        html += '</div>';
		                        
		                    	}
		                     }		
		                	
		    			    html += '</div>';	
		    			}
		    	           //在html中赋值，增加div选项卡
		    	           $('#divUserStop').html(html); 
		    		}else{		
						 var html = "";
					 	 html += "<div class='col-sm-12 text-center'>";
					 	 html += '<img style="width:50%;height:50%" src="<%=path%>/images/system/noEmployees.png" />';
					 	 html += "<p><span style='font-weight:bold;font-size:18px;'>抱歉，没有找到相关员工</span></p>";
					 	 html += "</div>";		
		           	     $('#divUserStop').html(html); 
			        }
		    	}); 
		}
		
		
		//停用账号选项卡,只有在用户点击停用账号时才会触发，提升加载效率
		function stopAccount(){
			//发送ajax请求，从DB中查询该企业下，正常的用户数量
			$("#userNumStop").text(initUserStopAndStartNum(1));		
		}
		
		
        //停用status=1 或启用 status = 0 或删除  status=3
        function stopOrStartUser(userId,status,account){
        	//停用逻辑
        	if(status == 1){
        	swal({
			  title: '停用账号后该员工账号将不可再次登录，确定停用吗？',
			  //text: "删除后将无法恢复，请谨慎操作！",
			  type: 'warning',
			  showCancelButton: true,
			  confirmButtonColor: '#d33',
			  cancelButtonColor: '#3085d6',
			  confirmButtonText: '确定',
			  cancelButtonText:'取消'
			}).then(function () {
				//发送ajax请求，修改用户状态
				ajaxOptionUser(userId,status,account);
			})
			//启用逻辑
        	}else if(status == 0){
            swal({
      		   title: '启用账号后此员工账号将恢复登录权限，确定启用吗？',
      		   type: 'warning',
      		   showCancelButton: true,
      		   confirmButtonColor: '#d33',
      		   cancelButtonColor: '#3085d6',
      		   confirmButtonText: '确定',
      		   cancelButtonText:'取消'
      		   }).then(function () {
      		   //发送ajax请求，启用用户状态
   				 ajaxOptionUser(userId,status,account);
      		   })	
        	}else if(status == 2){
            swal({
           	   title: '确定删除此账号吗？',
           	   type: 'warning',
           	   showCancelButton: true,
           	   confirmButtonColor: '#d33',
           	   cancelButtonColor: '#3085d6',
           	   confirmButtonText: '确定',
           	   cancelButtonText:'取消'
           	   }).then(function () {
           		 //发送ajax请求，删除用户状态
   				 ajaxOptionUser(userId,status,account);
           	   })	
        		
        	}
        	cancelBubble();
          }
        
        //根据状态操作用户 0启用 1停用 2删除
        function ajaxOptionUser(userId,status,account){
			 var url="<%=path%>/account/ajaxOptionUser";
			 var allUserNum = 0;
	         $.post(url, {
	        	 	"id":userId,
		        	"status":status,  //状态  0启用 1停用 2删除
		        	"account":account //给用户发通知使用
		    	 }, function(data) {
		    		var realData = data.data;
		    		if (data.status == 200) {
		    			//操作成功刷新页面
	 					window.location.reload();
		    		}else{		
			        	errorDialog(data.message);
			        }
		    	}); 
        }
        
        //毫秒转换成年月日
        Date.prototype.Format = function (fmt) { 
            var o = {  
                "M+": this.getMonth() + 1, //月份  
                "d+": this.getDate(), //日  
                "h+": this.getHours(), //小时  
                "m+": this.getMinutes(), //分  
                "s+": this.getSeconds(), //秒  
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
                "S": this.getMilliseconds() //毫秒  
            };  
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
            for (var k in o)  
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
            return fmt;  
        };  
        
        //监听给编辑按钮
        function initEditButtonMonitor(){
        	
      	  //机构被选中
      	  $('#mechanismCheckedEdit').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
      		$('#mechanismCheckedEdit').iCheck('check');
    		$('#teamCheckedEdit').iCheck('uncheck');
      	  }); 		
      	  
      	  //团队被选中
      	  $('#teamCheckedEdit').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
      		$('#mechanismCheckedEdit').iCheck('uncheck');
    		$('#teamCheckedEdit').iCheck('check');
      	  }); 	
      	  
        }
        
        //跳转到新增员工页面
        function addUserView(){
        	var baseTreeSelect = $("#baseTreeSelect").val();
        	window.location.href="<%=path%>/view/ui/createUser?baseTreeSelect="+baseTreeSelect;
        }
        
        //跳转到编辑员工页面
        function editUser(userId){
        	//是否可以跳转到编辑员工页面，需要加入shiro权限控制
        	<shiro:hasPermission name="org:manage_update">
        	window.location.href="<%=path%>/view/ui/updateUser?userId="+userId;
        	</shiro:hasPermission>
        	
        	cancelBubble();
        }

        //删除部门
        function delDepartment(){
			//部门信息编辑
			 var url="<%=path%>/department/alaxDeleteDepartment";
	         $.post(url, {
	        	 	"id":$("#baseTreeSelect").val()
		    	 }, function(data) {
		    		var realData = data.data;
		    		if (data.status == 200) {
		    			//操作成功刷新页面
	 					window.location.reload();
		    		}else{		
			        	errorDialog(data.message);
			        }
		    	}); 
        }
        
        //这里不放在jsp页面shiro标签无法过滤
		// 树删除操作  
		function beforeRemove(treeId, treeNode) {  
		var tag = 0;
	    <shiro:hasPermission name="org:delete_department">
	       	tag = 1;
	    </shiro:hasPermission>				
	    if(tag == 0){
	        errorDialog("您没有对部门的删除权限");	
	        return false;			
	    }
	        
        $("#baseTreeSelect").val(treeNode.id);
		$('#myModalDelete').modal('show');	
 		 return false;
		}  
		
		// 树编辑操作
		function beforeEditName(treeId, treeNode) {
		var tag = 0;
        <shiro:hasPermission name="org:update_department">
       		tag = 1;
        </shiro:hasPermission>	
        if(tag == 0){
        	errorDialog("您没有对部门的编辑权限");	
        	return false;
        }
		
		//选中机构								
		if(treeNode.companyType == 1){
		$('#mechanismCheckedEdit').iCheck('check');
		$('#teamCheckedEdit').iCheck('uncheck');
		//选中团队
		}else{
		$('#teamCheckedEdit').iCheck('check');
		$('#mechanismCheckedEdit').iCheck('uncheck');
		}
		
		var arrName = treeNode.title.split(",");
		$("#bmNameEdit").val(arrName[0]);
		$("#leaderNameEdit").val(treeNode.leaderName);
		$("#baseTreeEditSelect").val(treeNode.id);
		$('#myModalEdit').modal('show');	
		if(arrName[3] != "" && arrName[3] != null){
			var bmCodeEdit = [];
			bmCodeEdit = arrName[3].split(":");
			$("#bmCodeEdit").val(bmCodeEdit[1]);
		}
		
		return false;
		}  
		
		//初始化部门编号
		function initDepartNum(){
			var departCode = randomWord(true,6,6);
			$("#bmCode").val(departCode);
		}
		
		//导出部门
		function exportDepartment(){
			 window.location.href = "<%=path%>/department/exportDepartmentList";
		}
		
		//导入部门触发file
        function fileSelect() {
            document.getElementById("file").click();
            $("#submit").show();
        }
		
		//用户选中文件后回显	
        function fileSelected() {
        	var pathFile = $("#file").val().replace(/\\/g, "/");
        	var total = pathFile.length;
        	var firTotal = pathFile.lastIndexOf("/");
          // 文件选择后触发次函数
          $("#filePath").text(pathFile.substring(firTotal + 1,total));
        }
		
		//导入部门层级
		function importDepartment(){
			
            //导入部门层级调用的路径
            var url = "<%=path%>/department/importdepartment";		
            $(':file').fileupload({
        		replaceFileInput: false,
        		dataType: "json",
        		url : url,
        		add: function(e,data){
        			$("#submit").click(function(){
        				if($("#filePath").text() != "" && $("#filePath").text() != null){
            			  	$("#importAlertSpan").hide();
            			  	$("#closeRuleAlert").hide();			
            				$("#exportPro").show();					
            				data.formData = {}
            				data.submit();
        				}else{
        					$("#importAlertSpan").show();
        					$("#closeRuleAlert").hide();
        					$("#successShow").hide();
        					$("#errorShow").hide();
        				}

        			});
        		},
        		done : function(e,data) {
         			if(data.result.status == '200'){
        				$("#importAlertSpan").hide();
        			  	$("#closeRuleAlert").hide();
        			  	$("#importInfoDesc").hide();
        			  	$("#exportPro").hide();	
        				$("#successShow").show();
        				$("#sucNums").text(data.result.data.successImport);
        				$("#errNums").text(data.result.data.errorImport);
        			}else if(data.result.status == 3){
        				$("#errorShow").show();
        				$("#exportPro").hide();
        				$("#successShow").hide();
        			} 
        		}
        	});
			
		}
		
		  //关掉窗口并刷新
		function closeTabReload(){
			window.location.reload(); 
		}
		 
		//点击是否应用全员营销
		function clickBusiness(){
			var openAem = 0;
			if($("#businessSwitch").is(':checked')){
				openAem = 1;
			}else{
				openAem = 0;
			}
			
			//部门信息编辑
			 var url="<%=path%>/company/ajaxUpdateCompanyInfo";
	         $.post(url, {
	        	 	"openAem":openAem
		    	 }, function(data) {
		    		 //if(data.status == '200'){
		    		 //}
		    	}); 
		} 
		
		//打开部门设置
		function departmentSet(){
			//部门信息查询
			 var url="<%=path%>/company/ajaxCompanyInfo";
	         $.post(url, {
		    	 }, function(data) {
		    		 if(data.status == '200'){
		    			 if(data.data.openAem == 0){
		    				 $("#businessSwitch").attr("checked",false);
		    			 }else{
		    				 $("#businessSwitch").attr("checked",true);
		    			 }
		    		 }
		    	}); 
		}
		
		
		//导出无法导入的部门信息
		function exportError(){
			 //从redis中获取导出失败的数据
			 window.location.href = "<%=path%>/department/exportListError";
		}

       
    </script>					
</body>		
</html>
